	var num = 1;
	var num2=1;
	function appendConfig() {
		var configHtml="<table id=\""+num+"\" class=tab style=\"margin-top:10px\">\r\n"+
						"<tr>\r\n"+
							"<th>AppName</th>\r\n"+
							"<th>Operation</th>\r\n"+
							"<th>Properties</th>\r\n"+
						"</tr>\r\n"+
						"<tr>\r\n"+
							"<td><input type=\"text\"></td>\r\n"+
							"<td><select><option>ADD</option><option>UPDATE</option></select></td>\r\n"+
							"<td><input type=\"text\"></td>\r\n"+
						"</tr>\r\n"+
						"<tr>\r\n"+
							"<th>Key</th>\r\n"+
							"<th>Value</th>\r\n"+
							"<th></th>\r\n"+
						"</tr>\r\n"+
						"<tr>\r\n"+
							"<td><input type=\"text\"></td>\r\n"+
							"<td><input type=\"text\"></td>\r\n"+
							"<td><button onclick=\"addConfigValue("+num+")\">添加配置内容</button></td>\r\n"+
						"</tr>\r\n"+
					"</table>\r\n";
		$("#div2").append(configHtml);
		num++;
	}

	function addConfigValue(num){
		var configValueHtml="<tr id=\"v"+num2+"\">\r\n"+
							"<td><input type=\"text\"></td>\r\n"+
							"<td><input type=\"text\"></td>\r\n"+
							"<td><button onclick=\"deleteConfigValue("+num2+")\">删除配置内容</button></td>\r\n"+
						"</tr>";
		$("#"+num).append(configValueHtml);
		num2++;
	}

	function deleteConfigValue(num2){
		$("#v"+num2).remove();
	}

	function deleteConfig(){
		if (num!=1){
			$("#"+(num-1)).remove();
			num--;
		}
	}

	$(document).ready(function(){
		$.get('http://gitlab.idanlu.com/api/v3/projects/110/repository/branches?private_token=s6ds3VWzz6PAsBq_t9U4',function(data){
			for(var i=0;i<data.length;i++){
				$("#branchName").append("<option>"+data[i].name+"</option>");
			}
		}
		);
		//layer.load(0, {shade: [0.4,'#E8E8E8',true] });
		//layer.close();
		//alert("页面加载完成");
		/*layer.alert("提交成功，配置文件名："+"123", {
									closeBtn:0,
									icon: 6,
									skin: 'layer-ext-moon'
						},function(){
							alert('回调成功');
						});*/

	});

	function addAllConfigs(){
		var data=getData();
		var branchValue=document.getElementById("branchName").value;
		if (data!=0){
			var postData={
			"file_path": branchValue+getNowTime(),
			"branch_name": branchValue,
			"commit_message": "bug#14805",
			"content": data
			}
			$.ajax({
			type:"POST",
			url: "http://gitlab.idanlu.com/api/v3/projects/110/repository/files?private_token=s6ds3VWzz6PAsBq_t9U4",
			data: postData,
			beforeSend: function () {
				// 禁用按钮防止重复提交
				$("#subBtn").attr({ disabled: "disabled" });
				layer.load(0, {shade: [0.4,'#E8E8E8',true] });
			},
			success: function(data){
				layer.alert("提交成功，配置文件名："+data.file_path, {
									closeBtn:0,
									icon: 6,
									skin: 'layer-ext-moon'
						},function(){
							window.location.reload();
						});
				//window.location.reload();
			},
			complete: function () {
				layer.closeAll('loading');
			},
			error: function (data) {
			console.info("error: " + data.responseText);
			}
			});

			}
		}


	function getData(){
		var configProperties=[];
		for (var configNum=0;configNum<num;configNum++){
			var inputs=document.getElementById(configNum).getElementsByTagName("input");
			var selects=document.getElementById(configNum).getElementsByTagName("select");
			var selectValue=selects[0].value;
			var inputsValue=[];
			for (var i=0;i<inputs.length;i++){
				inputsValue.push(inputs[i].value);
			//alert(inputsValue);
			}
			var keyValue=[];
			var j=2;
			for (var i=1;i<(inputs.length)/2;i++){
				//校验value值中url的正确性
				if (inputsValue[j+1].indexOf(".idanlu.com")!=-1){
					var indexNum=inputsValue[j+1].indexOf(".idanlu.com");
					if ((indexNum-4)<0){
						layer.alert('输入URL错误！', {
									icon: 5,
									skin: 'layer-ext-moon'
						});
						$(inputs[j+1]).css("border","2px solid #FF0000");
						return 0;
					}
					else{
						if (inputsValue[j+1].substring((indexNum-4),indexNum)!=".env"){
							layer.alert('输入URL错误，请用环境参数！', {
									icon: 5,
									skin: 'layer-ext-moon'
							});
							$(inputs[j+1]).css("border","2px solid #FF0000");
							return 0;
						}
					}

				}
				//检验value值中jdbc的正确性
				if (inputsValue[j+1].indexOf("jdbc:mysql://")!=-1){
					var indexNum=inputsValue[j+1].indexOf("jdbc:mysql://");
					if (inputsValue[j+1].substr((indexNum+13),11)!="env_db:port"){
						layer.alert('输入jdbc地址错误,请用环境参数！', {
									icon: 5,
									skin: 'layer-ext-moon'
						});
						$(inputs[j+1]).css("border","2px solid #FF0000");
						return 0;
					}
				}
				//检验value值中是否含有ip地址
				var patt1=/(2[0-4]\d|25[0-5]|[01]\d\d|\d\d|\d)\.(2[0-4]\d|25[0-5]|[01]\d\d|\d\d|\d)\.(2[0-4]\d|25[0-5]|[01]\d\d|\d\d|\d)\.(2[0-4]\d|25[0-5]|[01]\d\d|\d\d|\d)/;
				if (patt1.test(inputsValue[j+1])==true){
					console.log(patt1.exec(inputsValue[j+1]));
					layer.alert('不允许输入ip地址！', {
								icon: 5,
								skin: 'layer-ext-moon'
					});
					$(inputs[j+1]).css("border","2px solid #FF0000");
					return 0;

				}

				keyValue+=(inputsValue[j]+"="+inputsValue[j+1]+"\n");
				j=j+2;
			}
			configProperties+=(inputsValue[0]+"::"+selectValue+"::"+inputsValue[1]+"\n"+
									"BEGIN\n"+
									keyValue+
									"END\n");
		}
		return configProperties;
	}

	function getNowTime(){
		var myDate = new Date();
		//获取当前年
		var year=myDate.getFullYear();
		//获取当前月
		var month=myDate.getMonth()+1;
		//获取当前日
		var date=myDate.getDate();
		var h=myDate.getHours();       //获取当前小时数(0-23)
		var m=myDate.getMinutes();     //获取当前分钟数(0-59)
		var s=myDate.getSeconds();
		var now=year+p(month)+p(date)+p(h)+p(m)+p(s);
		return now;
	}

	function p(s) {
		return s < 10 ? '0' + s: s;
	}


	function clearAll(){
		$("#div2 input").val("");
	}
